package com.ok.community.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ok.common.domain.po.Result;
import com.ok.community.domain.dto.OkCommentDto;
import com.ok.community.domain.po.OkComment;
import com.ok.community.service.IOkCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author lhw
 * @since 2024-05-12
 */
@Api(tags =  "Ok评论接口")
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class OkCommentController {

    private final IOkCommentService iOkCommentService;

    @ApiOperation("*发表评论")
    @PostMapping("/addComment")
    public Result addComment(@RequestBody OkCommentDto okCommentDto) {
        iOkCommentService.addComment(okCommentDto);
        return Result.success();
    }

    @ApiOperation("*根据帖子id获取评论")
    @GetMapping("/getComment")
    public Result getComment(@RequestParam Long cardId){
        LambdaQueryWrapper<OkComment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OkComment::getCardId,cardId);
        List<OkComment> list = iOkCommentService.list(queryWrapper);
        return Result.success(list);
    }
}
